/**
 * 使用说明：
 * 1）该维护方式适用于对多个项目进行统筹维护。
 * 2）使用时，首先为weihu.js创建一个公用的CDN链接；然后再在各个项目首页html文件中引入该js文件，即可实现公告的显示。
 * 3）当维护信息需要变更时，只需修改weihu.js中的公告内容即可。可配置公告覆盖哪些网站、公告文案等。
 **/

// 在html/body中引入：
{/* <script>
  (function(){
    const script=document.createElement('script');
    script.src ='https://jsxf-cdn-pub-1327400959.cos.ap-beijing.myqcloud.com/js/weihu.js?r=' + Math.random();
    document.body.appendChild(script);
  })();
</script> */}

// weihu.js内容：
(function() {
  // 公告标题
  let _announcementTitle = '服务维护公告';
  // 公告内容
  let _announcementContent = '为提供更优服务，2025年4月24 - 27日服务将维护升级，期间可能有短暂停服。不便之处，敬请谅解！';
  // 公告显示时间，单位：秒
  let _countdown = 5;
  // 要维护的域名白名单
  const whiteArr = [
    'jshx.jsxfedu.com',
    'bnuexam.jsxfedu.com',
    'jsjyzy.com',
    'm.jsjyzy.com',
  ];
  let flag = false;
  whiteArr.forEach(function (item) {
    if (item === window.location.host) {flag = true;}
  });
  if (!flag) return;
  // 创建公告容器元素
  const announcementContainer = document.createElement('div');
  announcementContainer.style.position = 'fixed';
  announcementContainer.style.top = '20px';
  announcementContainer.style.left = '50%';
  announcementContainer.style.transform = 'translateX(-50%)';
  announcementContainer.style.backgroundColor = '#fff';
  announcementContainer.style.padding = '20px';
  announcementContainer.style.borderRadius = '12px';
  announcementContainer.style.boxShadow = '0 8px 16px rgba(0, 0, 0, 0.15)';
  announcementContainer.style.zIndex = '9999';
  announcementContainer.style.maxWidth = '510px';
  announcementContainer.style.textAlign = 'center';
  announcementContainer.style.fontFamily = 'Inter, sans-serif';
  announcementContainer.style.border = '3px solid #FF6B6B';
  // 创建公告标题元素
  const announcementTitle = document.createElement('h1');
  announcementTitle.textContent = _announcementTitle;
  announcementTitle.style.color = '#FF6B6B';
  announcementTitle.style.fontSize = '28px';
  announcementTitle.style.marginBottom = '12px';
  announcementTitle.style.fontWeight = '600';
  // 创建公告内容元素
  const announcementContent = document.createElement('p');
  announcementContent.textContent = _announcementContent;
  announcementContent.style.color = '#333';
  announcementContent.style.fontSize = '18px';
  announcementContent.style.lineHeight = '1.6';
  // 创建关闭按钮元素
  const closeButton = document.createElement('button');
  closeButton.textContent = '关闭 (' + _countdown+ 's)';
  closeButton.style.marginTop = '20px';
  closeButton.style.padding = '10px 20px';
  closeButton.style.backgroundColor = '#FF6B6B';
  closeButton.style.color = 'white';
  closeButton.style.border = 'none';
  closeButton.style.borderRadius = '8px';
  closeButton.style.cursor = 'pointer';
  closeButton.style.transition = 'all 0.3s ease';
  closeButton.style.fontSize = '16px';
  closeButton.style.fontWeight = '500';
  closeButton.addEventListener('mouseover', function() {
    closeButton.style.backgroundColor = '#FF4747';
    closeButton.style.transform = 'scale(1.05)'
  });
  closeButton.addEventListener('mouseout', function() {
    closeButton.style.backgroundColor = '#FF6B6B';
    closeButton.style.transform = 'scale(1)'
  });
  closeButton.addEventListener('click', function() {
    announcementContainer.remove()
  });
  const countdownInterval = setInterval(function() {
    _countdown--;
    if (_countdown > 0) {
      closeButton.textContent = '关闭 (' + _countdown+ 's)'
    } else {
      clearInterval(countdownInterval);
      closeButton.textContent = '关闭';
      announcementContainer.remove()
    }
  }, 1e3);
  // 将元素添加到公告容器
  announcementContainer.appendChild(announcementTitle);
  announcementContainer.appendChild(announcementContent);
  announcementContainer.appendChild(closeButton);
  // 将公告容器添加到页面
  document.body.appendChild(announcementContainer)
})();
